#include "cybertron/sensor/noise/BrownNoise.hpp"
#include <algorithm>

CYBERTRON_BEGIN

BrownNoise::BrownNoise(float noisePerSquareHour/* = 5.0*/, float initialValue/* = 0.0*/)
	:TimeNoise(EBrownNoise), m_noisePerSquareHour(noisePerSquareHour), m_whiteNoise(0.0, 1.0)
{
	m_value = vec3(initialValue);
}

BrownNoise::~BrownNoise()
{
}

vec3 BrownNoise::update() {
	float sigma = (float)std::max(0.001, std::sqrt(elapsedTime()));
	resetTime();
	m_value += m_whiteNoise.update() * sigma * m_noisePerSquareHour / 60;
	return m_value;
}

CYBERTRON_END